<template>
  <transition name="input-animation">
    <div
      v-if="isShow"
      class="container-input input-transition"
    >
      <div class="item-input">
        <el-input
          :value="value"
          :type="type"
          :maxlength="maxlength"
          :placeholder="placeholder"
          :show-password="showPassword"
          clearable
          @input="onInput"
          @blur="onBlur"
          @clear="onClear"
        />
      </div>
      <div class="container-item-tip">
        <transition name="input-animation">
          <span
            v-if="tip"
            :class="['item-tip',state?'scucess':'error']"
          >{{tip}}</span>
        </transition>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  name: 'item-input',
  props: {
    showPassword: Boolean,
    isShow: [Boolean, String],
    state: [Boolean, String],
    maxlength: [Number, String],
    value: String,
    tip: String,
    type: {
      type: String,
      default: 'text',
    },
    placeholder: {
      type: String,
      default: '请输入...',
    },
  },
  methods: {
    onInput(value) {
      this.$emit('input', value);
    },
    onBlur() {
      this.$emit('blur');
    },
    onClear() {
      this.$emit('clear');
    },
  },
};
</script>

<style lang="less" spcoed>
.container-input {
  display: flex;
  flex-direction: column;
  .el-input.is-active .el-input__inner,
  .el-input__inner:focus {
    border-color: #817487;
  }
  .el-input__inner {
    border-width: 2px;
    border-radius: 30px;
    font-weight: bold;
    color: #817487;
  }
}
.item-input {
  height: 40px;
  padding-top: 20px;
}
.container-item-tip {
  height: 20px;
  padding: 6px 0 10px;
  box-sizing: border-box;
  line-height: 20px;
  font-size: 12px;
  user-select: none;
}
.item-tip {
  display: block;
  width: 100%;
  transition: all 0.8;
  position: relative;
  z-index: 10;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-weight: bold;
  &.scucess {
    color: #909399;
  }
  &.error {
    color: #f56c6c;
  }
}
</style>
